<?php
namespace app\index\controller;
use think\Config;
class Index extends Base
{



    public function index($key='')
    {

        $data = model('product')->homeGetShopProduct('system');
        $this->assign('products',$data['product']);
        $this->assign('shop',$data['shop']);
        $this->assign('key',$key);
        return view('index');
    }


    public function query($key='',$owner=''){


        $shop = model('shop')->getOwnerShop($owner);

        if( $owner == 'system'){
            $data = model('product')->homeGetShopProductBySearch($shop->id,$key);
            $this->assign('products',$data);
            $this->assign('shop',$shop);
            $this->assign('key',$key);
            return view('index');
        }
        else{
            $products = model('product')->getProductByShopId($shop->id);
            $shopComment = model('comment')->getShopComment($shop->id);
            if(!$shopComment){
                $rate = '100%';
            }
            else{
                $goodComment = model('comment')->getShopCommentByType($shop->id,0);
                $rate = 100 * count($goodComment)/count($shopComment);
                $rate = $rate.'%';
            }
            $this->assign('rate',$rate);
            $this->assign('productCount',count($products['products']));
            $this->assign('products',$products);
            $this->assign('shop',$shop);
            $this->assign('key',$key);
            return view('shop/index');
        }
    }









}
